#!/usr/bin/python
#-*-coding:utf-8-*-

import sys
from lib import *
from lib.pressureFunc import *

if __name__ == '__main__':
    name = 'aoTest2'
    password = '123456'
    startNum_total = 0
    endNum_total = 0
    groupNum_total = 0
    groupModel = 50

    if sys.argv[1]:
        name = sys.argv[1]
    if sys.argv[2]:
        password = sys.argv[2]
    if sys.argv[3]:
        startNum_total = int(sys.argv[3])
    if sys.argv[4]:
        endNum_total = int(sys.argv[4])
    if sys.argv[5]:
        groupNum_total = int(sys.argv[5])
    if len(sys.argv) == 7:
        voiceLength = int(sys.argv[6])
    else:
        voiceLength = 70

    groupModel = (endNum_total - startNum_total + 1)/groupNum_total

    voiceArray = []
    binfile = open('/home/fnadmin/workPathForFan/voiceTest/voice_60.spx', 'rb')
    try:
        while True:
            voiceData = binfile.read(29)
            if not voiceData:
                break
            voiceArray.append(voiceData)
            time.sleep(0.005)
    finally:
        binfile.close()

    cpuArray = []
    for i in range(groupNum_total):
        cpu = {}
        cpu["data"] = DataCenter()
        cpu["data"].voiceArray = voiceArray
        cpu["data"].voiceLength = voiceLength
        cpuArray.append(cpu)

    for i in range(groupNum_total):
        startNum = startNum_total + i*groupModel
        endNum = startNum + groupModel - 1
        groupNum = (groupNum_total -1)*groupModel + i
        groupNum = (startNum - 10001)/groupModel
        log.info("startNum:" + str(startNum) + " endNum:" + str(endNum))
        PT_getOnlineNumMax(cpuArray[i], name, password, startNum, endNum, groupNum)
    log.info("end to excute the function of PT_getOnlineNumMax...")